require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '10.0'

target 'ximalaya' do
  config = use_native_modules!

  use_react_native!(:path => config["reactNativePath"])

  target 'ximalayaTests' do
    inherit! :complete
    # Pods for testing
  end

#   Enables Flipper.

#   Note that if you have use_frameworks! enabled, Flipper will not work and
#   you should disable these next few lines.
#   #use_flipper!({ 'Flipper' => '0.74.0' })
#   # use_flipper!
#   use_flipper!({'Flipper-Folly' => '2.3.0' })
#   post_install do |installer|
# 	  flipper_post_install(installer)

# 	  ## Fix for Flipper-Folly on iOS 14.5
# 	  # find_and_replace("Pods/Flipper-Folly/folly/synchronization/DistributedMutex-inl.h",
# 	  #   "atomic_notify_one(state)", "folly::atomic_notify_one(state)")

# 	  # find_and_replace("Pods/Flipper-Folly/folly/synchronization/DistributedMutex-inl.h",
# 	  #   "atomic_wait_until(&state, previous | data, deadline)", "folly::atomic_wait_until(&state, previous | data, deadline)")
# 	end
end

target 'ximalaya-tvOS' do
  # Pods for ximalaya-tvOS

  target 'ximalaya-tvOSTests' do
    inherit! :search_paths
    # Pods for testing
  end
end



def find_and_replace(dir, findstr, replacestr)
  Dir[dir].each do |name|
      text = File.read(name)
      replace = text.gsub(findstr,replacestr)
      if text != replace
          puts "Fix: " + name
          File.open(name, "w") { |file| file.puts replace }
          STDOUT.flush
      end
  end
  Dir[dir + '*/'].each(&method(:find_and_replace))
end
